//用户账户api
import { http } from '../utils'

interface AccountDto {
    account: string,
    password: string,
    code: string
}

interface UpdateAccountDto {
    uuid: string,
    account: string,
    oldPassword: string,
    newPassword: string
}


interface UpdateUserInfo {
    uuid: string
    nickname?: string
    gender?: '男' | '女' | '保密'
    birthday?: string,
    email?: string,
    phone?: string,
    address?: string,
    introduction?: string,
    hobby?: Array<string>,
    profession?: string
    banned?: boolean
}

interface RegisterAccountDto {
    account: string,
    password: string,
}


//创建账户
export const registerAccount = (data: RegisterAccountDto) => http.post('/user-account', data)

//登录账户
export const loginAccount = (data: AccountDto) => http.post(`/user-account/login`, data);

//更新账户
export const editAccount = (data: UpdateAccountDto) => http.patch('/user-account', data)

//注销用户
export const delAccount = (data: string) => http.delete(`/user-account/${data}`)

//查找某个用户信息
export const findAccount = (data: { uuid: string }) => http.post(`/user-account/byUUID`, data)

//更新用户信息
export const editUserInfo = (data: UpdateUserInfo) => http.post('/user-account/updateUserInfo', data)

//查询所有用户
export const findAllCount = () => http.get('/user-account')


//用户收藏文章
export const collectionArticle = (data: { uuid: string, articleId: number }) => http.post('/user-account/collectionArticle', data)

//uuid获取用户收藏的所有文章
export const findAllCollectedArticle = (data: { uuid: string, keyword?: string }) => http.post('/user-account/collectedArticle', data)

//用户点赞文章
export const supportArticle = (data: { uuid: string, articleId: number }) => http.post('/user-account/supportArticle', data)


//关注作者
export const followUp = (data: { uuid: string, follow_uuid: string }) => http.post('/user-account/follow', data)

//删除浏览记录
export const delHistory = (delHistoryDto: { uuid: string, articleId: number }) => http.post('/user-account/delHistory', delHistoryDto)


//通知
export const addAnnouncement = (announcementDto: { id?: number, content: string,title:string }) => http.post('/user-account/announcement', announcementDto)
//获取通知
export const getAnnouncement = () => http.get('/user-account/getAnnouncement')